package com.bbs.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bbs.pojo.Message;
import com.bbs.pojo.dto.MessageDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MessageMapper extends BaseMapper<Message> {
    /**
     * 获取每个用户发送给该用户的消息中，最新的一条的未确认的。
     * 按时间排序。
     */
    @Select("select * from t_message m1 where receiver_id = #{receiverId} and type = #{type} and sent_time >= ALL(\n" +
            "\tselect sent_time from t_message m2 where receiver_id = #{receiverId} and type = #{type} and acknowledged = false and m1.sender_id = m2.sender_id\n" +
            ");")
    List<Message> getLastUserMessageGroupBySender(@Param("receiverId") String receiverId, @Param("type") Integer type);
}
